package handler

import (
	"github.com/gin-gonic/gin"
	"strconv"
	"choujiang/common/utils"
	"choujiang/box_server/service"
	"choujiang/common/models"
	"choujiang/common/consts"
)

func FeedbackAdd(c *gin.Context) {
	form := c.Request.Form
	uniqueId := form.Get("uniqueId")
	feedType := form.Get("feed_type")
	content := form.Get("content")
	contact := form.Get("contact")
	int64FeedType, _ := strconv.ParseInt(feedType, 10, 64)
	user := model.GetUserByUniqueId(uniqueId)
	if user == nil {
		utils.Error(consts.ErrUserNotFound, c)
		return
	}
	if feedType == "" || content == "" || contact == "" {
		utils.Error(consts.ErrInvalidParams, c)
		return
	}
	errType := service.CreateFeedback(user.Id, int64FeedType, content, contact)
	if errType != nil {
		utils.Error(errType, c)
		return
	}

	utils.JSON("ok", c)
}
